<!-- 修改密码页 -->
<template>
	<view class="uni-content">
		<!-- 顶部文字 -->
		<text class="uni-content-title-line mt10 mb20">修改登录密码</text>
		<uni-forms ref="form" :value="formData">
			<uni-forms-item name="oldPassword">
				<uni-easyinput class="input-box" type="password" v-model="formData.oldPassword" placeholder="请输入旧密码">
				</uni-easyinput>
			</uni-forms-item>
			<uni-forms-item name="newPassword">
				<uni-easyinput class="input-box" type="password" v-model="formData.newPassword" placeholder="请输入8-16位新密码">
				</uni-easyinput>
			</uni-forms-item>
			<uni-forms-item name="newPassword2">
				<uni-easyinput class="input-box" type="password" v-model="formData.newPassword2" placeholder="请再次输入新密码">
				</uni-easyinput>
			</uni-forms-item>
			<button class="blue-btn mt10 mb20" type="default" @click="submit">提 交</button>
		</uni-forms>
	</view>
</template>

<script>
	import passwordMod from '../common/js/passwordForChange.js'
	export default {
		data() {
			return {
				formData: {
					'oldPassword': '',
					'newPassword': '',
					'newPassword2': '',
				},
				rules: {
					oldPassword: {
						rules: [{
							required: true,
							errorMessage: '请输入旧密码',
						}]
					},
					...passwordMod.getPwdRules('newPassword', 'newPassword2')
				}
			}
		},
		onReady() {
			this.$refs.form.setRules(this.rules)
		},
		onShow() {},
		methods: {
			/**
			 * 完成并提交
			 */
			submit() {
				this.$refs.form.validate()
					.then(res => {
						uni.showLoading({
							title: '加载中'
						});
						let data = {
							oldPassword: this.formData.oldPassword,
							newPassword: this.formData.newPassword
						}
						this.$post(this.$api.system.user.profile.mobileUpdatePwd, data).then(res => {
							uni.showToast({
								title: "修改成功",
								icon: 'success'
							});
						}).catch(e => {
							uni.showToast({
								title: e.data.msg,
								icon: 'none'
							});
						})
					}).catch(errors => {
						console.log(errors);
					})
			},
			toUcenter() {
				uni.switchTab({
					url: "/pages/ucenter/ucenter"
				})
			}
		}
	}
</script>
<style lang="scss" scoped>
	@import "../common/style/uc-common.scss";
</style>
